<?php

namespace app\services;

use app\model\Ticket;

class TicketService
{

    /**
     * @var Ticket
     */
    private $dao;

    public function __construct()
    {
        $this->dao = new Ticket();
    }

    public function add($passengerList, $order_id, $seatArr){
        $result = [];
        foreach ($passengerList as $type => $passengerArr){
            foreach ($passengerArr as $passenger){
                $result[$passenger['name']] = $this->dao->create([
                    'order_id'=> $order_id,
                    'passenger_id'=> $passenger['id'],
                    'price'=> $seatArr[$type]['price'],
                    'sales_price'=> $seatArr[$type]['sales_price'],
                    'seat'=> $seatArr[$type]['seat'],
                ]);
            }
        }

        return $result;
    }

    public function loadPnr($order_id, $passenger_id_arr, $pnr, $big_pnr){
        return $this->dao->where(['order_id' => $order_id])->whereIn('passenger_id',$passenger_id_arr)->update([
            'pnr' =>$pnr,
            'big_pnr' =>$big_pnr
        ]);
    }


}